﻿<script language="jscript" runat="server">
function ActionTranslate(){
	this.empty=function(a){
		F.echo("没找到动作：" + a);
	};
}
ActionTranslate.prototype=new IAction(); //继承IAction对象，下面才可以直接用this.assign，this.display
ActionTranslate.prototype.Index=function(){
	Mo.Use("HttpRequest");
	var src = "我就像一只趴在玻璃上的苍蝇，前途一片光明，但又找不到出路！";
	var src_e = F.encode(src);
	var http = new MoLibHttpRequest("http://translate.google.cn/translate_a/t?client=t&sl=auto&tl=en&hl=en&sc=2&ie=UTF-8&oe=UTF-8&uptl=en&oc=1&otf=2&srcrom=1&ssel=0&tsel=0&q=" + src_e);
	http.header("Referer: http://translate.google.cn/?hl=en#auto/en/"+src_e);
	http.header("User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
	http.header("Accept-Language: zh-CN");
	http.header("Connection: Keep-Alive");
	if(http.getjson1("utf-8")){
		var ret = http.response;
		F.echo(src,true);
		var pinyin = ret[0][0][3];
		F.echo(pinyin,true);
		pinyin = pinyin.toLowerCase().replace(/(ā|á|ǎ|à)/igm,"a");
		pinyin = pinyin.replace(/(ō|ó|ǒ|ò)/igm,"o");
		pinyin = pinyin.replace(/(ē|é|ě|è)/igm,"e");
		pinyin = pinyin.replace(/(ī|í|ǐ|ì)/igm,"i");
		pinyin = pinyin.replace(/(ū|ú|ǔ|ù)/igm,"u");
		pinyin = pinyin.replace(/(ǖ|ǘ|ǚ|ǜ|ü)/igm,"v");
		F.echo(pinyin,true);
		pinyin = pinyin.replace(/(^|\s)([a-z])/igm,function(v){return v.toUpperCase();})
		F.echo(pinyin,true);
		pinyin = pinyin.replace(/[^a-z\s]/igm," ")
		F.echo(pinyin,true);
		F.echo(pinyin.replace(/\s/igm,""),true);
		F.echo(pinyin.replace(/\s/igm,"").toLowerCase(),true);
		F.echo(pinyin.replace(/\s/igm,"").toUpperCase(),true);
 
		//分词
		F.echo(ret[4].length+" = ");
		for(var i=0;i<ret[4].length;i++){
			F.echo("[" + i + "]"+ret[4][i][0]+" ");
		}
		F.echo("<br />");
		F.echo(ret[5].length+" = ");
		for(var i=0;i<ret[5].length;i++){
			F.echo("[" + i + "]"+ret[5][i][0]+" ");
		}
		//F.echo("<pre>");
		//F.dump(ret);
		//F.echo("<br />");
	}else{
		F.echo("</pre>");
	}
}
</script>
